<!-- @format -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Document</title>
</head>
<body>
<script src="flv.min.js"></script>
response   <span id="testStr"></span>
<button onclick="test()">测试</button>
<br/>
<video style="height: 900px;width: 1200px" id="videoElement1"></video>
<button onclick="playflv1()">播放1</button>
<script>

    function test(){
        const xhr = new XMLHttpRequest();
        xhr.open('GET', 'https://127.0.0.1:8085/jiangwei/flv/test', true); // true 表示异步请求
        xhr.onload = function() {
            if (xhr.status === 200) {
                document.getElementById('testStr').innerText = xhr.responseText;
                console.log(xhr.responseText); // 获取响应数据
            } else {
                console.error(xhr.statusText);
            }
        };
        xhr.onerror = function() {
            console.error(xhr.statusText);
        };
        xhr.send();
    }

    let flvPlayer
    if (flvjs.isSupported()) {
        flvLoad()
    }

    //自动播放,浏览器不支持
    function playflv1() {
        flvPlayer.play();
    }

    function flvLoad() {
        console.log("aa")
        let videoElement = document.getElementById('videoElement1');
        flvPlayer = flvjs.createPlayer({
            type: 'flv',
            url: 'https://127.0.0.1:8085/jiangwei/flv/test1',
        });
        flvPlayer.attachMediaElement(videoElement);
        flvPlayer.load();
    }

</script>
</body>
</html>